{extend name="platform/base" /}
{block name="resources"/}
<style type="text/css">
.required{
	color:red;margin-right:10px;
}
.error{
	font-size: 12px;
    line-height: 16px;
    color: red;
    margin-top: 10px;
	display:none;
}

/* 上传附件样式 */
.upload-btn-common {
    position: relative;
}
.upload-btn-common>div {
    position: absolute;
    cursor: pointer;
    z-index: 2;
    width: 44px;
    margin-left: 250px;
}
.upload-btn-common>div .input-file {
    opacity: 0;
    cursor: pointer;
    width: 100%;
    overflow: hidden;
}
.upload-btn-common>em {
    font-style: normal;
    background: #999;
    color: #fff;
    position: absolute;
    padding: 0 10px;
    z-index: 1;
    left: 250px;
	height: 30px;
    line-height: 30px;
}
.input-common{
	    border-radius: 0 !important;
    margin: 0 !important;
    border: 1px solid #D6D6D6 !important;
    box-shadow: none !important;
    font-size: 12px !important;
    width: 250px !important;
    padding: 0 6px !important;
    height: 30px !important;
    box-sizing: border-box;
    resize: none !important;
}
</style>
{/block}
{block name="main"}
<section class="panel panel-default">
	<header class="panel-heading font-bold"> 修改文章</header>
	<div class="panel-body">
		<form class="form-horizontal" id="form" name="form" onsubmit="">
		   <input type="hidden" value="{$article_id}" id="article_id"/>
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="required">*</span>文章标题</label>
				<div class="col-md-6">
					<input type="text" class="form-control" id="title" value="{$ArticleDetail.title}">
				</div>
				<p class="error">请输入文章标题</p>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">文章短标题</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="short_title" value="{$ArticleDetail.short_title}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">文章标签</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="tag"   value="{$ArticleDetail.tag}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<!-- 上传图片 -->
			<div class="form-group">
                                   <label class="col-sm-2 control-label">标题图片</label>
                                   <div class="col-sm-2">
                                   	<p class="imglogo-box">
                                   	       {if condition="$ArticleDetail.image eq ''"} 
										    	<img id="preview_Logo" src="" class="imglogo"> 
											{else/}
							 				    <img id="preview_Logo" src="{:__IMG($ArticleDetail.image)}" class="imglogo img-size"> 
											{/if} 
                                   	</p>
                                   	<a href="javascript:void(0);" style="display:block;position:relative;z-index:1;">
                                   		<span style="width: 97px;height: 34px;position: absolute;left: 0;top: 0;z-index: 2;cursor: pointer;"> 
                                   		<input hidefocus="true" size="1" class="input-file" name="file_upload"
					id="uploadImg" nc_type="change_store_label" type="file" style="width: 97px;height: 34px;padding: 0;margin: 0;border: none 0;opacity: 0;filter: alpha(opacity = 0);cursor: pointer;"
					onchange="imgUpload(this);"> 
					<input type="hidden" id="Logo" value="{$ArticleDetail.image}" />
				</span>
				<a class="btn btn-default"><i class="fa fa-cloud-upload text"></i><span class="text">上传图片</span></a>
		            	</a>
                                   </div>
            </div>
		
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">文章作者</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="author" value="{$ArticleDetail.author}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<label class="col-sm-2 control-label">文章来源</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="source"   value="{$ArticleDetail.source}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<label class="col-sm-2 control-label">文章来源链接</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="url" value="{$ArticleDetail.url}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="required">*</span>所属分类</label>
				<div class="col-sm-4">
					<select id="class_id" name="account" class="form-control m-b" onchange="error_hide()">
						<option value="0">请选择</option> 
						 {volist name="articleClassList['data']" id="vo"}
						 {if condition="$vo.pid eq 0"}
						<option value="{$vo.class_id}">{$vo.name}</option>
						 {/if} 
						 {volist name="articleClassList['data']" id="v2"}
							 {if condition="$vo.class_id eq $v2.pid"}
							<option value="{$v2.class_id}" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$v2.name}</option>
						    {/if} 
					    {/volist} {/volist}   
					    
					</select>
				</div>
				<p class="error">请选择所属分类</p>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">文章关键字</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="keyword" value="{$ArticleDetail.keyword}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				
                <label class="col-sm-2 control-label">文章摘要</label>
                <div class="col-md-4">
               <textarea id="summary"  cols="10" rows="10" class="form-control" style="max-width:755px;max-height:150px;">{$ArticleDetail.summary}</textarea>
               	</div>
                </div>
			<!-- 书签 -->
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">文章内容</label>
				<div class="col-md-4">
					<script id="editor" type="text/plain" style="height: 400px;width:750px;">{$ArticleDetail.content}</script>
					<p class="error"></p>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">文章附件</label>
				<div class="col-md-4">
					<div class="upload-btn-common">
						<div>
							<input class="input-file" name="file_upload" id="uploadAttachment" type="file" onchange="imgUpload(this);" title="上传" only-type=".zip">
							<input type="hidden" id="attachment" value="{$attachment_path}">
						</div>
						
						<input type="text" id="text_attachment" class="input-common" readonly="readonly" value="{$attachment_path}">
						<em>上传</em>								
					</div>
					<p class="hint">上传附件类型必须是<i class="important-note">zip</i>格式</p>
					<p class="error"></p>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<label class="col-sm-2 control-label">相关文章</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="article_id_array"   value="{$ArticleDetail.article_id_array}">
				</div>
			</div>
			
			<div class="line line-dashed line-lg pull-in"></div>
		       <div class="form-group">
				<label class="col-sm-2 control-label">是否允许推荐</label>
				<div class="col-md-4">
					<label class="radio-label" style="margin-bottom:10px;"><input type="radio" name="commend_flag" value="1"  id="enableYes" {if condition="$ArticleDetail['commend_flag'] eq 1"}checked{/if}>允许</label> 
					<label class="radio-label" style="margin-bottom:10px;"><input type="radio" name="commend_flag" value="0"  id="enableNo"  {if condition="$ArticleDetail['commend_flag'] eq 0"}checked{/if}>不允许</label>
				</div>
			</div>
	       <div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">是否允许评论</label>
				<div class="col-md-4">
					<label class="radio-label" style="margin-bottom:10px;"><input type="radio" name="comment_flag" value="1"  id="enableYes"  {if condition="$ArticleDetail['comment_flag'] eq 1"}checked{/if}>允许</label> 
					<label class="radio-label" style="margin-bottom:10px;"><input type="radio" name="comment_flag" value="0"  id="enableNo"  {if condition="$ArticleDetail['comment_flag'] eq 0"}checked{/if}>不允许</label>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<label class="col-sm-2 control-label">文章排序</label>
				<div class="col-md-1">
					<input type="number" min="0" class="form-control" id="sort"  value="{$ArticleDetail.sort}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<label class="col-sm-2 control-label">文章点击量</label>
				<div class="col-md-1">
					<input type="number" min="0" class="form-control" id="click" value="{$ArticleDetail.click}" >
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<label class="col-sm-2 control-label">文章评论数</label>
				<div class="col-md-1">
					<input type="number" min="0" class="form-control" id="comment_count" value="{$ArticleDetail.comment_count}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<label class="col-sm-2 control-label">文章分享数</label>
				<div class="col-md-1">
					<input type="number" min="0" class="form-control" id="share_count" value="{$ArticleDetail.share_count}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			
			
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<a href="javascript:void(0);" onclick="save(1)" class="btn btn-primary">修改文章</a>
					<a href="javascript:void(0);" onclick="save(2)" class="btn btn-primary">修改并预览</a>
				</div>
			</div>
		</form>
	</div>
</section>
   
{/block} 
{block name="script"}
<script src="PLATFORM_JS/ajaxFileUpload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.config.common.js"></script>
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.all.common.js"></script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/zh-cn.js"></script>
{include file="platform/openDialog" /}
  <script type="text/javascript">
  
  
  var ue = UE.getEditor('editor',{
		toolbars : [
			[ 'source', // 源代码
			'bold', // 加粗
			'italic', // 斜体
			'underline', // 下划线
			'strikethrough', // 删除线
			'forecolor', // 字体颜色
			'backcolor', // 背景色
			'fontfamily', // 字体
			'fontsize', // 字号
			'paragraph', // 段落格式
			'justifyleft', // 居左对齐
			'justifycenter', // 居中对齐
			'justifyright', // 居右对齐
			'superscript', // 上标
			'blockquote', // 引用
			'selectall', // 全选
			'preview', // 预览
			'removeformat', // 清除格式
			'inserttable', // 插入表格
			'unlink', // 取消链接
			'insertrow', // 前插入行
			'insertcol', // 前插入列
			'mergeright', // 右合并单元格
			'mergedown', // 下合并单元格
			'deleterow', // 删除行
			'deletecol', // 删除列
			'splittorows', // 拆分成行
			'splittocols', // 拆分成列
			'splittocells', // 完全拆分单元格
			'deletecaption', // 删除表格标题
			'inserttitle', // 插入标题
			'mergecells', // 合并多个单元格
			'deletetable', // 删除表格
			'cleardoc', // 清空文档
			'insertimage', // 多图上传
			'link', // 超链接
			'emotion', // 表情
			'insertorderedlist', // 有序列表
			'insertunorderedlist', // 无序列表
			'fullscreen', // 全屏
			'directionalityltr', // 从左向右输入
			'directionalityrtl', // 从右向左输入
			'imagenone', // 默认
			'imageleft', // 左浮动
			'imageright', // 右浮动
			// 'attachment', // 附件
			'imagecenter', // 居中
			'lineheight', // 行间距
			'customstyle', // 自定义标题
			]]
	});

  $(function(){
		UE.getEditor('editor').addListener( 'ready', function() {
			if($("#content").val()){
				UE.getEditor('editor').setContent($("#content").val());
			}
		} );
	})
	
  window.onload=function(){
	  $("#class_id").val({$ArticleDetail.class_id});
  }
	var flag = false;//防止重复提交
     function save(type){
    	 var comment_flag=$("input[name='comment_flag']:checked").val();
    	 var commend_flag=$("input[name='commend_flag']:checked").val();
    	 
         var article_id=$("#article_id").val();
    	 var title=$("#title").val();
    	 var class_id=$("#class_id").val();
    	 var short_title=$("#short_title").val();
    	 var source=$("#source").val();
    	 var url=$("#url").val();
    	 var author=$("#author").val();
    	 var summary=$("#summary").val();
    	 var content = UE.getEditor('editor').getContent();
 		if(content.length>30000){
 			showTip("文章内容太长","warning");
 			return;
 		}
    	 var image=$("#Logo").val();
    	 var keyword=$("#keyword").val();
    	 var article_id_array=$("#article_id_array").val();
    	 var click=$("#click").val();
    	 var sort=$("#sort").val();
    	 var tag=$("#tag").val();
    	 var comment_count=$("#comment_count").val();
    	 var share_count=$("#share_count").val();
      	 
       	var attachment_path = $("#attachment").val();
    if(verify(title,class_id)){
    	if(flag){
			return;
		}
		flag = true;
    	$.ajax({
    		type:"post",
    	    url:"{:__URL('PLATFORM_MAIN/Cms/ajax_updateArticle')}",
    	    data:{
    	      'article_id':article_id,
    	      'title':title,   
    	      'class_id':class_id,
    	      'short_title':short_title,
    	      'source':source,
    	      'url':url,
    	      'author':author,
    	      'summary':summary,
    	      'content':content,
    	      'image':image,
    	      'keyword':keyword,
    	      'article_id_array':article_id_array,
    	      'click':click,
    	      'sort':sort,
    	      'commend_flag':commend_flag,
    	      'comment_flag':comment_flag,
    	      'attachment_path':attachment_path,
    	      'tag':tag,
    	      'comment_count':comment_count,
    	      'share_count':share_count
    	     
    	},
    	    async : true,
    	    success:function(data){
    			   //alert(JSON.stringify(data)); 
    	    		if (data["code"] > 0) {
    						showMessage('success', data["message"]);
    						if(type==2 && article_id>0){
    							location.href = __URL("SHOP_MAIN/cms/articleClassInfo?article_id="+article_id);
    						}else if(type==1){
    							location.href = "{:__URL('PLATFORM_MAIN/Cms/articleList')}";	
    						}
    						
    					}else{
    						showMessage('error', data["message"]);
    					}
    	    }
    	
    	});
    	 
    	} 
     }
    /**
  	*模块输入信息验证
  	*/
  	function verify(title,class_id,content){
 		if(title==''){
 		$("#title").parent().next(".error").show();
   		 $("#title").focus();
   		 return false;
   	 }else{
			$(".error").hide();
		}
   	 if(class_id==0){
   		$("#class_id").parent().next(".error").show();
   		 $("#class_id").focus();
   		 return false;
   	 }else{
			$(".error").hide();
		}
   	 
   	 return true;
 	}             
  	 //上传方法
 	function imgUpload(event) {
 		var fileid = $(event).attr("id");
 		var data = new Object();
 		var id = $(event).next().attr("id");
 		var only_type = $(event).attr('only-type');
 		if(!only_type){
 			data.file_path = UPLOADCOMMON;
 		}else{
 			data.file_path = UPLOADFILE;
 		}
 		uploadFile(fileid,data,function(res){
 			
 			if(res.code){
 				$("#" + id).val(res.data);
 				$("#text_" + id).val(res.data);
 				$("#preview_"+ id).attr("src",__IMG(res.data));
 				showTip(res.message,"success");
 			}else{
 				showTip(res.message,"error");
 			}
 		});
 	}

 	/**
 	 * 删除文件
 	 * @param {Object} file_url
 	 * @param {Object} even
 	 */
 	function delete_file(file_url,even){
 		$.ajax({
 			type:"post",
 			url:"{:__URL('ADMIN_MAIN/system/delete_file')}",
 			data:{'file_url':file_url},
 			dataType:'json',
 			success:function(data){
 				if (data['code']>0) {
 					$( "#dialog" ).dialog({
 						buttons: {
 							"确定,#01B044": function() {
 								$(this).dialog('close');
 							}
 						},
 						contentText:"附件移除成功",
 							time:1,
 					});
 					$(even).parent().empty();
 				}else{
 					$( "#dialog" ).dialog({
 						buttons: {
 							"确定,#0059d6,#fff": function() {
 								$(this).dialog('close');
 							}
 						},
 						contentText:data['message'],
 					});
 				}
 			}
 		});
 	}
    </script>
  
{/block}